<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<style>
    .form-group {
        margin-top: 10px;
    }

    .staffApply {
        float: left;
        margin-left: 20px;
    }
</style>
<script type="text/javascript">
    //手术项目动态行
    var idNum = 0;
    function addOperationApply() {
        var idNum = 0;
        function addOperationSchedule(i) {
            idNum=$('#operationName').children('tr').length;
            alert(idNum);
            var leftHtml = "";
            leftHtml += '<tr><input type="hidden" name="operationNameBefores[' + idNum + '].id"/><td><select  name="operationNameBefores[' + idNum + '].operationName" class="form-control" cssStyle="border: none;margin:0;"><option value="" label="" selected="selected"/>'+
            <c:forEach items="${operationDictList.list}" var="operationDict">
            '<option items="${operationDict.operationName}" itemLabel="label" itemValue="value" htmlEscape="false">${operationDict.operationName}</option>'+</c:forEach>
            '</select></td><td class="col-sm-5"><select name="operationNameBefores[' + idNum + '].operationScale" class="form-control scale"><option value=""></option>' +
            <c:forEach items="${fns:getDictList('OPERATION_SCALE')}" var="type">
            '<option value="${type.value}">${type.label}</option>' +
            </c:forEach>
            '</select></td><td class="col-sm-2"><select name="operationNameBefores[' + idNum + '].woundGrade" class="form-control"><option value=""></option>' +
            <c:forEach items="${fns:getDictList('WOUND_GRADE_DICT')}" var="type">
            '<option value="${type.value}">${type.label}</option>' +
            </c:forEach>
            '</select></td>'
            leftHtml = leftHtml + '<td><button type="button" class="btn btn-danger" onclick="delOperationApply(this)">删除</button>' +
            '</td></tr>'
            $('#operationName').append(leftHtml);
            idNum = idNum + 1;
        }
    }
    function delOperationApply(obj) {
        $(obj).parent().parent().remove();
    }
    //医生助手动态行
    var num = "";
    num = ${operatiSize}+1 - 1;
    function addStaffApply(obj, type) {
        var leftHtml = ''
        leftHtml += '<div class="staffApply col-sm-4">' +
        '<div class="col-sm-8"><input name="operationAssistants[' + num + '].operationLocal" value="' + type + '" class="form-control" type="hidden"/>' +
        '<input class="form-control" name="operationAssistants[' + num + '].user.id" type="text" onclick="assignButton(\'' + 'doczs' + num + '\')" value="分配人员"/></div>' +
        '<button type="button" class="btn btn-danger col-sm-2" onclick="delStaffApply(this)">删除</button>' + '</div>';
        $(obj).parent().before(leftHtml);
        num = num + 1;
    }
    //供应护士动态行
    var gYnum = 1;
    function operationGYNurses(obj, type) {
        var leftHtml = ''
        leftHtml += '<div class="staffApply col-sm-4">' +
        '<div class="col-sm-8"><input name="operationGYNurses[' + gYnum + '].operationLocal" value="' + type + '" class="form-control" type="hidden"/>' +
        '<input class="form-control" name="operationGYNurses[' + gYnum + '].user.name" type="text" onclick="assignButton(\'' + 'doczs' + gYnum + '\')" value="分配人员"/></div>' +
        '<button type="button" class="btn btn-danger col-sm-2" onclick="delStaffApply(this)">删除</button>' + '</div>';
        $(obj).parent().before(leftHtml);
        gYnum = gYnum + 1;
    }
    //上台护士动态行
    var sTnum = 1;
    function operationSTNurses(obj, type) {
        var leftHtml = ''
        leftHtml += '<div class="staffApply col-sm-4">' +
        '<div class="col-sm-8"><input name="operationSTNurses[' + sTnum + '].operationLocal" value="' + type + '" class="form-control" type="hidden"/>' +
        '<input class="form-control" name="operationSTNurses[' + sTnum + '].user.name" type="text" onclick="assignButton(\'' + 'doczs' + sTnum + '\')" value="分配人员"/></div>' +
        '<button type="button" class="btn btn-danger col-sm-2" onclick="delStaffApply(this)">删除</button>' + '</div>';
        $(obj).parent().before(leftHtml);
        sTnum = sTnum + 1;
    }
    function delStaffApply(obj, i) {
        $(obj).parent().remove();
        num -= 1;
    }

    /*分配人员*/
    function assignButton(inputShow, inputHide) {
        var userIds = $("#" + inputHide).val();
        layerTree = layer.open({
            title: '分配人员',
            type: 2,
            area: ['500px', '520px'],
            fixed: false, //不固定
            maxmin: true,
            content: '${ctx}/sys/orgRole/usertorole?userId=' + userIds,
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                console.log(inputShow+"+++++"+inputHide)
                var resultIds = $(layero).find("iframe")[0].contentWindow.resultIds;
                var resultNames = $(layero).find("iframe")[0].contentWindow.resultNames;
                $("#" + inputShow).val(resultNames);
                $("#" + inputHide).val(resultIds);
                layer.close(index);
            }, no: function (index) {
                layer.close(index);
            }
        });
    }

    function openCosts(masterId){
        return loadDivForm('mainCenterDiv','searchForm','${ctx}/operation/operationCosts/findByMaster?masterId='+masterId);
    }

</script>
<div class="content-wrap">
    <div class="wrapper" style="bottom: 50px;">
        <ul class="nav nav-tabs">
            <li class="active">
                <a href="#">术后登记</a>
            </li>
        </ul>
        <section class="main-content col-lg-12">
            <div class="content-wrap">
                <c class="panel-body">
                    <form:form id="inputForm" data-parsley-validate="" modelAttribute="operationMaster"
                               onsubmit="return formSaveLoad('mainCenterDiv','inputForm','${ctx}/operation/operationMaster/save','${ctx}/operation/operationMaster/index');"
                               method="post" class="form-horizontal">
                        <form:hidden path="id"/>
                        <form:hidden path="clinicId"/>
                        <form:hidden path="patientId"/>
                    <fieldset>
                        <legend><img src="${ctxStatic}/images/left.png" class="pull-left mt8">手术项目<img
                                src="${ctxStatic}/images/right.png" class="pull-right mt8"></legend>
                        <table class="table table-bordered table-striped mg-t datatable">
                            <thead>
                            <tr>
                                <td>手术名称</td>
                                <td>手术等级</td>
                                <td>切口等级</td>
                                <td>操作</td>
                            </tr>
                            </thead>
                            <tbody id="operationName">
                            <!--手术修改-->
                                <c:forEach items="${operationMaster.operationNameAfterList}"
                                           varStatus="operationName"
                                           var="operationNameAfter">
                                    <tr>
                                        <td>
                                            <form:hidden
                                                    path="operationNameBefores[${operationName.index}].id"></form:hidden>
                                            <form:select data-parsley-validate=""
                                                         path="operationNameAfterList[${operationName.index}].operationName"
                                                         class="form-control" data-parsley-required=""
                                                         cssStyle="border: none;margin:0;">
                                                <option value="" label="" selected="selected"/>
                                                <c:forEach items="${operationDictList.list}"
                                                           var="operationDict">
                                                    <option items="${operationDict.operationName}"
                                                            itemLabel="label"
                                                            itemValue="value"
                                                            htmlEscape="false">${operationDict.operationName}</option>
                                                </c:forEach>
                                            </form:select>
                                        </td>

                                        <td>
                                            <form:select data-parsley-validate=""
                                                         path="operationNameAfterList[${operationName.index}].operationScale"
                                                         class="form-control" data-parsley-required=""
                                                         cssStyle="border: none;margin:0;">
                                                <option value="" label="" selected="selected"/>
                                                <c:forEach items="${fns:getDictList('OPERATION_SCALE')}" var="type">
                                                    <c:choose>
                                                        <c:when test="${type.value==operationNameAfter.operationScale}">
                                                            <option value="${type.value}"
                                                                    selected="selected">${type.label}</option>
                                                        </c:when>
                                                        <c:otherwise>
                                                            <option value="${type.value}">${type.label}</option>
                                                        </c:otherwise>
                                                    </c:choose>

                                                </c:forEach>
                                            </form:select>
                                        </td>
                                        <td>
                                            <select name="operationNameAfterList[${operationName.index}].woundGrade"
                                                    class="form-control">
                                                <c:forEach items="${fns:getDictList('WOUND_GRADE_DICT')}"
                                                           var="type">
                                                    <c:choose>
                                                        <c:when test="${type.value==operationNameAfter.woundGrade}">
                                                            <option value="${type.value}"
                                                                    selected="selected">${type.label}</option>
                                                        </c:when>
                                                        <c:otherwise>
                                                            <option value="${type.value}">${type.label}</option>
                                                        </c:otherwise>
                                                    </c:choose>

                                                </c:forEach>
                                            </select>
                                        </td>
                                        <td>
                                            <button type="button" class="btn btn-danger"
                                                    onclick="delOperationApply(this)">删除
                                            </button>
                                        </td>
                                    </tr>
                                </c:forEach>

                            </tbody>
                        </table>
                        <div class="button_position">
                            <div class="pull-right">
                                <button type="button" class="btn btn-primary" onclick="addOperationApply(this)">
                                    新增
                                </button>
                            </div>
                        </div>
                    </fieldset>
                    <fieldset>
                        <legend><img src="${ctxStatic}/images/left.png" class="pull-left mt8">手术基本信息<img
                                src="${ctxStatic}/images/right.png" class="pull-right mt8"></legend>
                        <div class="col-lg-12">
                            <div class="form-group col-sm-12">
                                <label class="col-sm-2 control-label">术前诊断：</label>
                                <div class="col-sm-10">
                                    <form:textarea path="diagBeforeOperation" value="" htmlEscape="false"
                                                   maxlength="2000" class="form-control"/>
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                <label class="col-sm-2 control-label">术后诊断：</label>
                                <div class="col-sm-10">
                                    <form:textarea path="diagAfterOperation" value="" htmlEscape="false"
                                                   maxlength="2000" class="form-control"/>
                                </div>
                            </div>
                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">预约时间：</label>

                                <div class="col-sm-8">
                                    <fmt:formatDate value="${operationMaster.makeDate}"
                                                    pattern="yyyy-MM-dd HH:mm:ss" var="date"/>
                                    <input name="makeDate" htmlEscape="false" class="form-control Wdate"
                                           data-parsley-required="true" readonly
                                           onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                           value="${date}"/>
                                </div>
                            </div>
                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">手术时间：</label>

                                <div class="col-sm-8">
                                    <fmt:formatDate value="${operationMaster.scheduledDate}"
                                                    pattern="yyyy-MM-dd HH:mm:ss" var="date"/>
                                    <input name="scheduledDate" htmlEscape="false" class="form-control Wdate"
                                           data-parsley-required="true" readonly
                                           onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                           value="${date}"/>
                                </div>
                            </div>
                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">手术室：</label>

                                <div class="col-sm-8">
                                    <form:select data-parsley-validate=""
                                                 path="operatingRoomId"
                                                 class="form-control" data-parsley-required=""
                                                 cssStyle="border: none;margin:0;">
                                        <form:option value="" label=""/>
                                        <c:forEach items="${orgDeptList.list}" var="orgDept">
                                            <form:option value="${orgDept.id}" itemLabel="label"
                                                         itemValue="value"
                                                         htmlEscape="false">
                                                ${orgDept.deptName}
                                            </form:option>
                                        </c:forEach>
                                    </form:select>
                                </div>
                            </div>
                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">手术间：</label>

                                <div class="col-sm-8">
                                    <form:select data-parsley-validate=""
                                                 path="operatingRoomNo"
                                                 class="form-control" data-parsley-required=""
                                                 cssStyle="border: none;margin:0;">
                                        <option value="" label=""/>
                                        <c:forEach items="${operationRoomList.list}" var="operationRoom">
                                            <form:option value="${operationRoom.id}" itemLabel="label"
                                                         itemValue="value" htmlEscape="false">
                                                ${operationRoom.roomNo}
                                            </form:option>
                                        </c:forEach>
                                    </form:select>
                                </div>
                            </div>
                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">隔离等级：</label>
                                <div class="col-sm-8">

                                    <form:select path="isolationIndicator" class="form-control"
                                                 data-parsley-required="true" cssStyle="border: none;margin:0;"
                                                 itemValue="${fns:getDictLabels(operationApplyChange.isolationIndicator, 'QUARANTINE_MARK', '')}">
                                        <form:option value="" label=""/>
                                        <form:options items="${fns:getDictList('QUARANTINE_MARK')}"
                                                      itemLabel="label"
                                                      itemValue="value" htmlEscape="false"/>
                                    </form:select>
                                </div>
                            </div>
                            <form:hidden path="inoroutFlag"/>
                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">输/供血方式：</label>
                                <div class="col-sm-8">
                                    <form:select path="provideWay"
                                                 itemValue="${fns:getDictLabels(operationApplyChange.provideWay, 'BLOOD_SUPPLY_WAY', '')}"
                                                 class="form-control" data-parsley-required="true"
                                                 cssStyle="border: none;margin:0;">
                                        <form:option value="" label=""/>
                                        <form:options items="${fns:getDictList('BLOOD_SUPPLY_WAY')}"
                                                      itemLabel="label"
                                                      itemValue="value" htmlEscape="false"/>
                                    </form:select>
                                </div>
                            </div>
                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">病情：</label>

                                <div class="col-sm-8">
                                    <form:select path="patientCondition"
                                                 itemValue="${fns:getDictLabels(operationApplyChange.patientCondition, 'PATIENT_CONDITION', '')}"
                                                 class="form-control" data-parsley-required="true"
                                                 cssStyle="border: none;margin:0;">
                                        <form:option value="" label=""/>
                                        <form:options items="${fns:getDictList('PATIENT_CONDITION')}"
                                                      itemLabel="label"
                                                      itemValue="value" htmlEscape="false"/>
                                    </form:select>
                                </div>
                            </div>
                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">麻醉方式：</label>

                                <div class="col-sm-8">
                                    <form:select path="anesthesiaMethod"
                                                 itemValue="${fns:getDictLabels(operationApplyChange.anesthesiaMethod, 'ANESTHESIA_METHOD', '')}"
                                                 class="form-control" data-parsley-required="true"
                                                 cssStyle="border: none;margin:0;">
                                        <form:option value="" label=""/>
                                        <form:options items="${fns:getDictList('ANESTHESIA_METHOD')}"
                                                      itemLabel="label"
                                                      itemValue="value" htmlEscape="false"/>
                                    </form:select>
                                </div>
                            </div>
                        </div>
                    </fieldset>

                    <fieldset>
                        <legend><img src="${ctxStatic}/images/left.png" class="pull-left mt8">手术人员信息<img
                                src="${ctxStatic}/images/right.png" class="pull-right mt8"></legend>
                        <div class="col-sm-12">
                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">主刀医生：</label>

                                <div class="col-sm-8">
                                    <form:hidden path="zdStaffBefore.userId" id="zdDoctor"></form:hidden>
                                    <input type="hidden" name="zdStaffBefore.operationLocal" value="0"
                                           class="form-control"/>
                                    <input class="form-control" id="zdDoctorName"
                                           value="${operationMaster.zdStaffBefore.userNames}" type="text"
                                           onclick="assignButton('zdDoctorName','zdDoctor')" placeholder="分配人员"/>
                                </div>
                            </div>
                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">麻醉医生：</label>

                                <div class="col-sm-8">
                                    <form:hidden path="myStaffBefore.userId" id="myDoctor"></form:hidden>
                                    <input name="myStaffBefore.operationLocal" value="1" class="form-control"
                                           type="hidden"/>
                                    <input class="form-control" id="myDoctorName"
                                           value="${operationMaster.myStaffBefore.userNames}" type="text"
                                           onclick="assignButton('myDoctorName','myDoctor')" placeholder="分配人员"/>
                                </div>
                            </div>
                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">输血医生：</label>

                                <div class="col-sm-8">
                                    <form:hidden path="sxStaffBefore.userIds" id="sxDoctor"></form:hidden>
                                    <input name="sxStaffBefore.operationLocal" value="2" class="form-control"
                                           type="hidden"/>
                                    <input class="form-control" id="sxDoctorNames"
                                           value="${operationMaster.sxStaffBefore.userNames}" type="text"
                                           onclick="assignButton('sxDoctorNames','sxDoctor')" placeholder="分配人员"/>
                                </div>
                            </div>

                            <div class="form-group col-sm-6">
                                <label class="col-sm-4 control-label">麻醉助手：</label>

                                <div class="col-sm-8">
                                    <form:hidden path="mzStaffBefore.userIds" id="mzDoctor"></form:hidden>
                                    <input name="mzStaffBefore.operationLocal" value="3" class="form-control"
                                           type="hidden"/>
                                    <input class="form-control" id="mzDoctorNames"
                                           value="${operationMaster.mzStaffBefore.userNames}" type="text"
                                           onclick="assignButton('mzDoctorNames','mzDoctor')" placeholder="分配人员"/>
                                </div>
                            </div>
                            <div class="form-group col-sm-10">
                                <label class="col-sm-2 control-label">医生助手：</label>

                                <div class="col-sm-8">
                                    <form:hidden path="yzStaffBefore.userIds" id="yzDoctor"></form:hidden>
                                    <input name="yzStaffBefore.operationLocal" value="4" class="form-control"
                                           type="hidden"/>
                                    <input class="form-control" id="yzDoctorNames"
                                           value="${operationMaster.yzStaffBefore.userNames}" type="text"
                                           onclick="assignButton('yzDoctorNames','yzDoctor')" placeholder="分配人员"/>
                                </div>
                            </div>
                            <div class="form-group col-sm-10">
                                <label class="col-sm-2 control-label">上台护士：</label>

                                <div class="col-sm-8">
                                    <form:hidden path="stStaffBefore.userIds" id="stDoctor"></form:hidden>
                                    <input name="stStaffBefore.operationLocal" value="5" class="form-control"
                                           type="hidden"/>
                                    <input class="form-control" id="stDoctorNames"
                                           vlaue="${operationMaster.stStaffBefore.userNames}" type="text"
                                           onclick="assignButton('stDoctorNames','stDoctor')" placeholder="分配人员"/>
                                </div>
                            </div>
                            <div class="form-group col-sm-10">
                                <label class="col-sm-2 control-label">供应护士：</label>

                                <div class="col-sm-8">
                                    <form:hidden path="gyStaffBefore.userIds" id="gyDoctor"></form:hidden>
                                    <input name="gyStaffBefore.operationLocal" value="6" class="form-control"
                                           type="hidden"/>
                                    <input class="form-control" id="gyDoctorNames"
                                           value="${operationMaster.gyStaffBefore.userNames}" type="text"
                                           onclick="assignButton('gyDoctorNames','gyDoctor')" placeholder="分配人员"/>
                                </div>
                            </div>
                        </div>
                    </fieldset>

                    <div class="form-group" style="margin-top: 15px;margin-left: 10px">
                        <div class="col-sm-10">
                            <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存">&nbsp;

                            <c:if test="${operationMaster.id!=null and operationMaster.id!=''}">
                                <input id="btnCancel" class="btn" type="button" value="划 价" onclick=openCosts(${operationMaster.id})>
                            </c:if>
                        </div>
                    </div>
                    </form:form>
            </div>
        </section>
    </div>
</div>



